/**
 * 
 */
package org.minuzy.demo.controller;

import javax.servlet.http.HttpServletResponse;

import org.minuzy.demo.service.UserService;
import org.minuzy.demo.vo.JsonVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;

/**
 * @author minuzy
 * 
 */
@Controller
public class UserController {

	@Autowired
	private UserService userService;

	@ResponseBody
	@RequestMapping(value = "/login", method = RequestMethod.GET)
	public String test(@RequestParam(required = true) String username,
			HttpServletResponse response) {

		int len = userService.getUsernameLength(username);

		JsonVO json = new JsonVO();
		if (len > 3)
			json.setSuccess(true);
		else
			json.setSuccess(false);

		return JSON.toJSONString(json);
	}

	@RequestMapping("/")
	public String root() {
		return "redirect:/index";
	}

	@RequestMapping("/index")
	public String index() {
		return "index";
	}
}
